﻿Imports KOR.Helpers

Namespace BL

    Public Module Products



#Region "Products_DML"

        Public Function InsertProduct(dict As Dictionary(Of String, Object)) As Integer
            Return DDA.Insert("Products", dict)
        End Function

        Public Function UpdateProduct(dict As Dictionary(Of String, Object), ProductID As Integer) As Integer
            Return DDA.Update("Products", dict, "ProductID=" & ProductID)
        End Function

        Public Function DeleteProduct(ByVal ProductID As Integer) As Integer
            Return DDA.Delete("Products", "ProductID=" & ProductID, False)
        End Function

#End Region

#Region "Products_Selection"

        Public Function GetAllProducts() As IDataReader
            Dim sql As String = "SELECT * FROM Products Order By ProductID DESC"
            Return DDA.SelectData(sql)
        End Function

        Public Function GetProducts(searchFor As String, criteria As String, startRowIndex As Integer, maximumRows As Integer, SortBy As String) As IDataReader
            Dim sql As String
            sql = "SELECT * FROM Products "

            If SortBy = "" Then SortBy = " CreatedDate Desc"

            Return DDA.SelectDataPaginated(sql, startRowIndex, maximumRows, SortBy)
        End Function

        Public Function ProductsCount(searchFor As String, criteria As String) As Integer
            Dim sql As String
            sql = "SELECT * FROM Products "
            Return DDA.SelectDataCount(sql)
        End Function

        Public Function GetProductByProductID(ProductID As Integer) As IDataReader
            Dim sql As String = "SELECT * FROM Products WHERE ProductID = " & ProductID
            Return DDA.SelectData(sql)
        End Function

        Public Function GetFileIdsByProductID(ProductID As Integer) As String
            Dim retVal As String = ""
            Using reader As IDataReader = GetProductByProductID(ProductID)
                If reader.Read Then
                    retVal = ValueOrDefault(reader("FileIds"), "").ToString
                End If
                reader.Close()
            End Using
            Return retVal
        End Function

#End Region




    End Module

End Namespace
